{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": "    name   age  gender isMarried\n0   John  20.0       0       yes\n1   Mike  32.0       0       yes\n2  Mozla  29.0       1        no\n3   Rose   NaN       1       yes\n4  David  15.0       0        no\n5  Marry  28.0       1        no\n6  Wansi  21.0       0        no\n7   Sidy  30.0       0       yes\n8   Jack  37.0       1        no\n9   Alic  25.0       1        no",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>name</th>\n      <th>age</th>\n      <th>gender</th>\n      <th>isMarried</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>John</td>\n      <td>20.0</td>\n      <td>0</td>\n      <td>yes</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>Mike</td>\n      <td>32.0</td>\n      <td>0</td>\n      <td>yes</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>Mozla</td>\n      <td>29.0</td>\n      <td>1</td>\n      <td>no</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>Rose</td>\n      <td>NaN</td>\n      <td>1</td>\n      <td>yes</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>David</td>\n      <td>15.0</td>\n      <td>0</td>\n      <td>no</td>\n    </tr>\n    <tr>\n      <th>5</th>\n      <td>Marry</td>\n      <td>28.0</td>\n      <td>1</td>\n      <td>no</td>\n    </tr>\n    <tr>\n      <th>6</th>\n      <td>Wansi</td>\n      <td>21.0</td>\n      <td>0</td>\n      <td>no</td>\n    </tr>\n    <tr>\n      <th>7</th>\n      <td>Sidy</td>\n      <td>30.0</td>\n      <td>0</td>\n      <td>yes</td>\n    </tr>\n    <tr>\n      <th>8</th>\n      <td>Jack</td>\n      <td>37.0</td>\n      <td>1</td>\n      <td>no</td>\n    </tr>\n    <tr>\n      <th>9</th>\n      <td>Alic</td>\n      <td>25.0</td>\n      <td>1</td>\n      <td>no</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "#创建一组数据\n",
    "data = {'name': ['John', 'Mike', 'Mozla', 'Rose', 'David', 'Marry', 'Wansi', 'Sidy', 'Jack', 'Alic'],\n",
    "        'age': [20, 32, 29, np.nan, 15, 28, 21, 30, 37, 25],\n",
    "        'gender': [0, 0, 1, 1, 0, 1, 0, 0, 1, 1],\n",
    "        'isMarried': ['yes', 'yes', 'no', 'yes', 'no', 'no', 'no', 'yes', 'no', 'no']}\n",
    "#标签 index索引\n",
    "label = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']\n",
    "df = pd.DataFrame(data)\n",
    "# print(df.loc[:,'name'])\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "print(df.iloc[1:2,:1])"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "print(df.loc[:,'age'])"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "df.name"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "df.age"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "df.gender"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "outputs": [
    {
     "data": {
      "text/plain": "    name   age  gender isMarried\n0   John  20.0       0       yes\n1   Mike  32.0       0       yes\n2  Mozla  29.0       1        no\n3   Rose   NaN       1       yes\n4  David  15.0       0        no\n5  Marry  28.0       1        no\n6  Wansi  21.0       0        no\n7   Sidy  30.0       0       yes\n8   Jack  37.0       1        no\n9   Alic  25.0       1        no",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>name</th>\n      <th>age</th>\n      <th>gender</th>\n      <th>isMarried</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>John</td>\n      <td>20.0</td>\n      <td>0</td>\n      <td>yes</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>Mike</td>\n      <td>32.0</td>\n      <td>0</td>\n      <td>yes</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>Mozla</td>\n      <td>29.0</td>\n      <td>1</td>\n      <td>no</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>Rose</td>\n      <td>NaN</td>\n      <td>1</td>\n      <td>yes</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>David</td>\n      <td>15.0</td>\n      <td>0</td>\n      <td>no</td>\n    </tr>\n    <tr>\n      <th>5</th>\n      <td>Marry</td>\n      <td>28.0</td>\n      <td>1</td>\n      <td>no</td>\n    </tr>\n    <tr>\n      <th>6</th>\n      <td>Wansi</td>\n      <td>21.0</td>\n      <td>0</td>\n      <td>no</td>\n    </tr>\n    <tr>\n      <th>7</th>\n      <td>Sidy</td>\n      <td>30.0</td>\n      <td>0</td>\n      <td>yes</td>\n    </tr>\n    <tr>\n      <th>8</th>\n      <td>Jack</td>\n      <td>37.0</td>\n      <td>1</td>\n      <td>no</td>\n    </tr>\n    <tr>\n      <th>9</th>\n      <td>Alic</td>\n      <td>25.0</td>\n      <td>1</td>\n      <td>no</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "outputs": [
    {
     "data": {
      "text/plain": "    name   age\n0   John  20.0\n1   Mike  32.0\n2  Mozla  29.0\n3   Rose   NaN\n4  David  15.0\n5  Marry  28.0\n6  Wansi  21.0\n7   Sidy  30.0\n8   Jack  37.0\n9   Alic  25.0",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>name</th>\n      <th>age</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>John</td>\n      <td>20.0</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>Mike</td>\n      <td>32.0</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>Mozla</td>\n      <td>29.0</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>Rose</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>David</td>\n      <td>15.0</td>\n    </tr>\n    <tr>\n      <th>5</th>\n      <td>Marry</td>\n      <td>28.0</td>\n    </tr>\n    <tr>\n      <th>6</th>\n      <td>Wansi</td>\n      <td>21.0</td>\n    </tr>\n    <tr>\n      <th>7</th>\n      <td>Sidy</td>\n      <td>30.0</td>\n    </tr>\n    <tr>\n      <th>8</th>\n      <td>Jack</td>\n      <td>37.0</td>\n    </tr>\n    <tr>\n      <th>9</th>\n      <td>Alic</td>\n      <td>25.0</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[['name','age'],]#df[a,b,c,d] a决定读取的列（名）  df['name']   X = name         df[['name','age']] ->  X = name + age  df[X]#决定读取的列"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "outputs": [
    {
     "data": {
      "text/plain": "    name   age\n0   John  20.0\n1   Mike  32.0\n2  Mozla  29.0\n3   Rose   NaN\n4  David  15.0\n5  Marry  28.0\n6  Wansi  21.0\n7   Sidy  30.0\n8   Jack  37.0\n9   Alic  25.0",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>name</th>\n      <th>age</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>John</td>\n      <td>20.0</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>Mike</td>\n      <td>32.0</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>Mozla</td>\n      <td>29.0</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>Rose</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>David</td>\n      <td>15.0</td>\n    </tr>\n    <tr>\n      <th>5</th>\n      <td>Marry</td>\n      <td>28.0</td>\n    </tr>\n    <tr>\n      <th>6</th>\n      <td>Wansi</td>\n      <td>21.0</td>\n    </tr>\n    <tr>\n      <th>7</th>\n      <td>Sidy</td>\n      <td>30.0</td>\n    </tr>\n    <tr>\n      <th>8</th>\n      <td>Jack</td>\n      <td>37.0</td>\n    </tr>\n    <tr>\n      <th>9</th>\n      <td>Alic</td>\n      <td>25.0</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[['name','age']]"
   ],
   "metadata": {
    "collapsed": false
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
